<script lang="ts" setup>
import { ref } from 'vue'
import { ElTable } from 'element-plus'

interface Props {
  title?: string
}
const props = withDefaults(defineProps<Props>(), {
  title: '默认标题'
})


interface User {
  date: string
  name: string
  address: string
}

const currentRow = ref()
const singleTableRef = ref<InstanceType<typeof ElTable>>()

const setCurrent = (row?: User) => {
  singleTableRef.value!.setCurrentRow(row)
}
const handleCurrentChange = (val: User | undefined) => {
  currentRow.value = val
}
const tableData: User[] = [
  {
    date: '2016-05-03',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    date: '2016-05-02',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    date: '2016-05-04',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    date: '2016-05-01',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
]

</script>

<template>
  <div class="table">
    <div class="title">{{ props.title }}</div>
    <el-table class="test" ref="singleTableRef" :data="tableData" highlight-current-row style="width: 100%"
      @current-change="handleCurrentChange">
      <el-table-column type="index" width="50" />
      <el-table-column property="date" label="Date" width="120" />
      <el-table-column property="name" label="Name" width="120" />
      <el-table-column property="address" label="Address" />
      <el-table-column property="address" label="Address" />
      <el-table-column property="address" label="Address">
        <el-button>编辑</el-button>
        <el-button type="danger">删除</el-button>
      </el-table-column>
    </el-table>
  </div>
</template>

<style lang="scss" scoped>
.table {
  background-color: rgba(255, 255, 255, .8);
  padding: 20px 40px;
  padding-bottom: 30px;
  border-radius: 15px;
  height: auto;
  overflow: hidden;
  max-height: 100%;
  overflow-y: auto;
  box-shadow: 0 0 2px 2px rgb(236, 236, 236);
}

.title {
  color: grey;
  position: relative;
  height: 20px;
  line-height: 20px;

  &::before {
    content: '';
    position: absolute;
    width: 5px;
    background-color: rgb(183, 183, 231);
    height: inherit;
    border-radius: 5px;
    left: -10px;

  }
}
</style>